﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

using System;
using System.Windows;
using System.Windows.Interactivity;
using System.Windows.Media;

namespace TheOliver.Controls
{
    public class ScaleAnimation : TargetedTriggerAction<FrameworkElement>
    {
        // properties
        public TimeSpan Time { get; set; } // how long must the animation take
        public double ScaleSize { get; set; } // the size that the choosen control must scale to

        // invoke method wil execute the behaviour
        protected override void Invoke(object parameter)
        {
            // get the element
            FrameworkElement myElement = this.AssociatedObject as FrameworkElement;

            // create a new ScaleTransform
            myElement.RenderTransformOrigin = new Point(0.5, 0.5);
            ScaleTransform st = new ScaleTransform();
            myElement.RenderTransform = st;

            // play the animation
            Animation.playAnimation(myElement.Name, "(UIElement.RenderTransform).(ScaleTransform.ScaleX)", this.Time, this.ScaleSize);
            Animation.playAnimation(myElement.Name, "(UIElement.RenderTransform).(ScaleTransform.ScaleY)", this.Time, this.ScaleSize);
        }
    }
}
